//
//  QQTableViewCell.m
//  UI12_homework_2
//
//  Created by dllo on 15/11/10.
//  Copyright (c) 2015年 ZKJ. All rights reserved.
//

#import "QQTableViewCell.h"
#import "UIImageView+WebCache.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@implementation QQTableViewCell

- (void)dealloc {
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.imageViews];
        [self.imageViews release];
        
        [self addSubview:self.label1];
        [self.label1 release];
        
        [self addSubview:self.label2];
        [self.label2 release];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageViews.frame = CGRectMake(HEIGHT / 4, 0, HEIGHT, HEIGHT);
    self.label1.frame = CGRectMake(HEIGHT * 3 / 2, 0, WIDTH - HEIGHT * 4 / 3, HEIGHT / 2);
    self.label2.frame = CGRectMake(HEIGHT * 3 / 2, HEIGHT / 2, WIDTH - HEIGHT * 4 / 3, HEIGHT / 2);
}

- (UIImageView *)imageViews {
    if (!_imageViews) {
        _imageViews = [[UIImageView alloc] initWithFrame:CGRectZero];
        _imageViews.layer.cornerRadius = HEIGHT * 2 / 3;
        _imageViews.layer.masksToBounds = YES;
    }
    return _imageViews;
}

- (UILabel *)label1 {
    if (!_label1) {
        _label1 = [[UILabel alloc] initWithFrame:CGRectZero];
        _label1.font = [UIFont systemFontOfSize:20];
    }
    return _label1;
}

- (UILabel *)label2 {
    if (!_label2) {
        _label2 = [[UILabel alloc] initWithFrame:CGRectZero];
    }
    return _label2;
}

- (void)setSecondModel:(SecondModel *)secondModel {
    if (secondModel != _secondModel) {
        [_secondModel release];
        _secondModel = [secondModel retain];
    }
    self.label1.text = _secondModel.src;
    self.label2.text = _secondModel.title;
    [self.imageViews sd_setImageWithURL:[NSURL URLWithString:_secondModel.picCover]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
